import math
'''
#def 函数名():
def print_menu():
    print("-"*50)
    print("1.add a name")
    print("2.delete a name")
    print("3.amend a name")
    print("4.query a name")
    print("5.exit program")
    print("-"*50)

print_menu()


def sum_2_num(a,b):
    result = a+b
    print("%d + %d = %d"%(a,b,result))

num1 = int(input("请输入第一个数字："))
num2 = int(input("请输入第二个数字："))
sum_2_num(num1,num2)

def get_temp(temp):
    print("当前的温度是%d"%temp)
    return temp

def get_temp_fehren(temp):
    temp_tehren = 32 + temp * 1.8
    print("当前的华氏摄氏度是%d"%temp_tehren)

temp = int(input("请输入当前的温度："))
get_temp_fehren(get_temp(temp))


def test():
    a = 10
    b = 20
    c = 30
    d = [a,b,c]
    #return  [a,b,c]
    #return  (a,b,c)
    #return  a,b,c#封装成元组
    return d

num = test()
print(num)


def test1():
    print("-----1-1-----")
    test2()
    print("-----1-2-----")
def test2():
    print("-----2-1-----")
    print("-----2-2-----")
def test3():
    print("-----3-1-----")
    print("-----3-2-----")
def test4():
    print("-----4-1-----")
    print("-----4-2-----")

test1()


def print_line():
    print("*"*50)

def print_5_line():
    i = 0
    while i < 5:
        print_line()
        i += 1

print_5_line()

#局部变量

#全局变量
a = 100
def test1():
    global a
    a = 66
def test2():
    print("a = %d"%a)
test1()
test2()

a = 1
def test1():
    print("a = %d" % a)
    print("b = %d" % b)
    #print("c = %d" % c)
b = 2
test1()
#c = 3函数调用前定义变量都可以被调用


#名片管理系统

card_list = []

def print_menu():
    """完成打印名片菜单"""
    print("-" * 50)
    print("1.add a name")
    print("2.find a name")
    print("3.all names")
    print("4.exit program")
    #print("5.exit program")
    print("-" * 50)

def add_new_card_list():
    """完成添加一个新的名片"""
    new_name = input("请输入要添加的名字:")
    new_qq = input("请输入要添加的qq:")
    new_tele = input("请输入要添加的电话:")
    new_addr = input("请输入要添加的地址:")
    new_card = {"name": new_name, "qq": new_qq, "tele": new_tele, "addr": new_addr}
    global card_list
    card_list.append(new_card)

def find_card_list():
    """用来查询一个名字"""
    global card_list
    find_name = input("请输入要查找的姓名")
    find_flag = 0
    for temp in card_list:
        if find_name == temp["name"]:
            print("%s\t%s\t%s\t%s"%(temp['name'],temp['qq'],temp['tele'],temp['addr']))
            find_flag = 1
            break
    if find_flag == 0:
        print("查无此人")

def show_all_card_list():
    """遍历所有的名字"""
    global card_list
    print("姓名\tqq\ttele\taddr")
    for temp in card_list:
        print("%s\t%s\t%s\t%s"%(temp['name'],temp['qq'],temp['tele'],temp['addr']))

def main():
    """完成对整个程序的控制"""
    print_menu()

    while True:
        #获取用户的功能号
        num = int(input("请输入选择的功能："))

        #进行判断，并执行相应的功能
        if num == 1:
            add_new_card_list()
        elif num == 2:
            find_card_list()
        elif num == 3:
            show_all_card_list()
        elif num == 4:
            break
        else:
            print("输入有误，请重新输入......")

main()
'''
'''
#缺省参数,只能放在后边
def test(a,b=10):
    result = a+b
    print(result)

test(11)
test(20,22)
test(20)

def test1(a,b=10,c=20):
    print(a)
    print(b)
    print(c)

test1(11,c=30)
'''
'''
#不定长参数
def sum_nd_nums(a,b,*args):
    print(a)
    print(b)
    print(args)
    result = a+b
    for num in args:
        result+=num
    print("result = %d"%result)
    print("-"*50)

sum_nd_nums(11,22,33,44,55,66,77)
def sum_nd_nums(a,b,c=33,*args,**kwargs):
    print(a)
    print(b)
    print(c)
    print(args)
    print(kwargs)

sum_nd_nums(11,22,33,44,55,66,task=44,done=55)
A=(44,55,66)
B={"name":"laowang","age":18}
sum_nd_nums(11,22,33,*A,**B)
'''
'''
#引用
a = [11,22,33]
b = a
print(a)
print(b)
a.append(44)
print(a)
print(b)

#可变类型，不可变类型
#不可变类型：数字，字符串，元组
#可变类型：字典，列表
infor = {"name":"laowang",100:"haha"}

#递归
def getnums(num):
    if num > 1:
        return num*getnums(num-1)
    else:
        return num
print(getnums(4))

'''

#abs max int float str bool
a = abs
print(a(-1))
#把一个整数转换成十六进制表示的字符串
n = 255
print(str(hex(n)))

def my_abs(x):
    if x >= 0:
        return x
    else:
        return -x

#空函数
def nop():
    pass

#只允许整数和浮点数类型的参数，数据检查类型用isinstance
def my_abs_2(x):
    if not isinstance(x,(int,float)):
        raise TypeError('Bad operand type')
    if x >= 0:
        return x
    else:
        return -x

def move(x,y,step,angle = 0):
    nx = x + step * math.cos(angle)
    ny = y - step * math.sin(angle)
    return nx,ny
#返回多值其实是返回一个元组
x,y = move(100,100,60,math.pi/6)
print(x,y)
r = move(100,100,60,math.pi/6)
print(r)

def quadratic(a,b,c):
    x = b*b - 4*a*c
    x1 = ((-b) + math.sqrt(x))/(2*a)
    x2 = ((-b) - math.sqrt(x))/(2*a)
    return x1,x2

#默认参数
def power(x,n=2):
    s = 1
    while n > 0:
        n = n - 1
        s = s * x
    return s

print(power(5))
print(power(5,3))

def enroll(name,gender,age=6,city='Beijing'):
    print('name:',name)
    print('gender:',gender)
    print('age:',age)
    print('city:',city)




